package com.pw.study.mr.relation;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.Arrays;


public class MapperByRelation  extends Mapper<LongWritable,Text,Text, Text> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        System.out.println("key................."+key);
        if(key.get()==0){
            System.out.println("............................");
        }
        String[] split = value.toString().split("\t");
        String[] split1 = split[1].split(",");
        Arrays.sort(split1);//排序去重
        for (int i = 0; i < split1.length-1; i++) {//利用两个for循环对结果一一匹配
            for (int j = i+1; j < split1.length; j++) {
                context.write(new Text(split1[i]+"-"+split1[j]),new Text(split[0]));
                System.out.println((split1[i]+"-"+split1[j])+"\t"+split[0]);
            }
        }
    }
}
